#include <bits/stdc++.h>
// 2025/01/21
// tag: 
// Author: Zhang Muen
using namespace std;

int n, m, parents[20001], enemy[20001];

class UF
{
public:
    int cnt;

    UF(int n)
    {
        cnt = n;
        for (int i = 0; i <= n; i++)
            parents[i] = i;
    };

    int find(int i)
    {
        if (parents[i] != i)
            return parents[i] = find(parents[i]);
        return parents[i];
    }

    void un(int i, int j)
    {
        int ri = find(i), rj = find(j);
        if (ri == rj)
            return;
        parents[ri] = rj;
        cnt--;
    }

    int count()
    {
        return cnt;
    }

    bool connected(int p, int q)
    {
        return find(p) == find(q);
    }
};

struct Edge{
    int a, b, w;
} g[100001];

bool cmp(const Edge& a, const Edge& b){
    return a.w > b.w;
}

signed main()
{
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
        cin >> g[i].a >> g[i].b >> g[i].w;
    sort(g + 1, g + m + 1, cmp);
    UF uf(n);
    for (int i = 1; i <= m; i++){
        if (uf.connected(g[i].a, g[i].b)){
            cout << g[i].w << endl;
            return 0;
        }
        if (!enemy[g[i].a])
            enemy[g[i].a] = g[i].b;
        else
            uf.un(enemy[g[i].a], g[i].b);
        if (!enemy[g[i].b])
            enemy[g[i].b] = g[i].a;
        else
            uf.un(enemy[g[i].b], g[i].a);
    }
    cout << 0 << endl;
    return 0;
}